package com.pig4cloud.common.seate.properties;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.h2.security.auth.ConfigProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;

@Data
@Accessors(chain = true)
@NoArgsConstructor
@ConfigurationProperties("spring.seate.registry")
public class SeateRegisterProperties {

    /**
     * type : file
     * nacos : {"application":"seata-server","serverAddr":"localhost","namespace":"","cluster":"default","username":"","password":""}
     * eureka : {"serviceUrl":"http://localhost:8761/eureka","application":"default","weight":"1"}
     * redis : {"serverAddr":"localhost:6379","db":0,"password":"","cluster":"default","timeout":0}
     * zk : {"cluster":"default","serverAddr":"127.0.0.1:2181","sessionTimeout":6000,"connectTimeout":2000,"username":"","password":""}
     * consul : {"cluster":"default","serverAddr":"127.0.0.1:8500"}
     * etcd3 : {"cluster":"default","serverAddr":"http://localhost:2379"}
     * sofa : {"serverAddr":"127.0.0.1:9603","application":"default","region":"DEFAULT_ZONE","datacenter":"DefaultDataCenter","cluster":"default","group":"SEATA_GROUP","addressWaitTime":"3000"}
     * file : {"name":"file.conf"}
     * config : {"type":"file","nacos":{"serverAddr":"localhost","namespace":"","group":"SEATA_GROUP","username":"","password":""},"consul":{"serverAddr":"127.0.0.1:8500"},"apollo":{"appId":"seata-server","apolloMeta":"http://192.168.1.204:8801","namespace":"application"},"zk":{"serverAddr":"127.0.0.1:2181","sessionTimeout":6000,"connectTimeout":2000,"username":"","password":""},"etcd3":{"serverAddr":"http://localhost:2379"},"file":{"name":"file.conf"}}
     */

    private String type = "file";
    private NacosProperties nacos = new NacosProperties();
    private EurekaProperties eureka = new EurekaProperties();
    private RedisProperties redis = new RedisProperties();
    private ZkProperties zk = new ZkProperties();
    private ConsulProperties consul = new ConsulProperties();
    private Etcd3Properties etcd3 = new Etcd3Properties();
    private SofaProperties sofa = new SofaProperties();
    private FileProperties file = new FileProperties();
//    private ConfigProperties config = new ConfigProperties();

    @Data
    @Accessors(chain = true)
    @NoArgsConstructor
    public static class NacosProperties {
        /**
         * application : seata-server
         * serverAddr : localhost
         * namespace :
         * cluster : default
         * username :
         * password :
         */

        private String application = "seata-server";
        private String serverAddr = "localhost";
        private String namespace = "";
        private String cluster = "default";
        private String username = "";
        private String password = "";
    }

    @Data
    @Accessors(chain = true)
    @NoArgsConstructor
    public static class EurekaProperties {
        /**
         * serviceUrl : http://localhost:8761/eureka
         * application : default
         * weight : 1
         */

        private String serviceUrl = "http://localhost:8761/eureka";
        private String application = "default";
        private int weight = 1;
    }

    @Data
    @Accessors(chain = true)
    @NoArgsConstructor
    public static class RedisProperties {
        /**
         * serverAddr : localhost:6379
         * db : 0
         * password :
         * cluster : default
         * timeout : 0
         */

        private String serverAddr = "localhost:6379";
        private int db = 0;
        private String password = "";
        private String cluster = "default";
        private int timeout = 0;
    }

    @Data
    @Accessors(chain = true)
    @NoArgsConstructor
    public static class ZkProperties {
        /**
         * cluster : default
         * serverAddr : 127.0.0.1:2181
         * sessionTimeout : 6000
         * connectTimeout : 2000
         * username :
         * password :
         */

        private String cluster = "default";
        private String serverAddr = "127.0.0.1:2181";
        private int sessionTimeout = 6000;
        private int connectTimeout = 2000;
        private String username = "";
        private String password = "";
    }

    @Data
    @Accessors(chain = true)
    @NoArgsConstructor
    public static class ConsulProperties {
        /**
         * cluster : default
         * serverAddr : 127.0.0.1:8500
         */

        private String cluster = "default";
        private String serverAddr = "127.0.0.1:8500";
    }

    @Data
    @Accessors(chain = true)
    @NoArgsConstructor
    public static class Etcd3Properties {
        /**
         * cluster : default
         * serverAddr : http://localhost:2379
         */

        private String cluster = "default";
        private String serverAddr = "http://localhost:2379";
    }

    @Data
    @Accessors(chain = true)
    @NoArgsConstructor
    public static class SofaProperties {
        /**
         * serverAddr : 127.0.0.1:9603
         * application : default
         * region : DEFAULT_ZONE
         * datacenter : DefaultDataCenter
         * cluster : default
         * group : SEATA_GROUP
         * addressWaitTime : 3000
         */

        private String serverAddr = "127.0.0.1:9603";
        private String application = "default";
        private String region = "DEFAULT_ZONE";
        private String datacenter = "DefaultDataCenter";
        private String cluster = "default";
        private String group = "SEATA_GROUP";
        private int addressWaitTime = 3000;
    }

    @Data
    @Accessors(chain = true)
    @NoArgsConstructor
    public static class FileProperties {
        /**
         * name : file.conf
         */

        private String name = "file.conf";
    }

}
